package com.example.campus_activity_backend.controller;

import com.example.campus_activity_backend.common.BaseResponse;
import com.example.campus_activity_backend.common.BatchAuditRequest;
import com.example.campus_activity_backend.common.ErrorCode;
import com.example.campus_activity_backend.common.ResultUtil;
import com.example.campus_activity_backend.domain.Student;
import com.example.campus_activity_backend.exception.BusinessException;
import com.example.campus_activity_backend.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/student")
@RestController
public class StudentController {
    @Autowired
    private StudentService studentService;

    @PostMapping("/add")
    public BaseResponse<Long> addStudent(@RequestBody Student student){
        if(student == null){
            throw new BusinessException(ErrorCode.PARAMS_ERROR);
        }
        long id = studentService.addStudent(student);
        return ResultUtil.success(id);
    }

    @PutMapping("/audit/{studentId}/{status}")
    public BaseResponse<Boolean> auditStudent(@PathVariable Integer studentId,@PathVariable Integer status){
        if(studentId == null || status == null){
            throw new BusinessException(ErrorCode.PARAMS_ERROR);
        }
        boolean rseult = studentService.auditStudent(studentId, status);
        return ResultUtil.success(rseult);
    }


    @PutMapping("/audit/batch")
    public BaseResponse<Boolean> batchAuditStudent(@RequestBody BatchAuditRequest request) {
        if(request.getStudentIdList() == null || request.getStatus() == null){
            throw new BusinessException(ErrorCode.PARAMS_ERROR);
        }
        boolean result = studentService.batchAuditStudent(request.getStudentIdList(), request.getStatus());
        return ResultUtil.success(result);
    }

}
